package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminCategoryController")
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    /**
     * 新增分类
     * @param dto
     * @return
     */
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO dto) {
        return categoryService.addCategory(dto);
    }


    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Result pageQuery(CategoryPageQueryDTO dto){
        return categoryService.pageQuery(dto);

    }

    /**
     * 根据id删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteById(Long id){
        return categoryService.deleteById(id);
    }


    /**
     * 修改类型
     * @param dto
     * @return
     */
    @PutMapping
    public Result updateType(@RequestBody CategoryDTO dto){
        return categoryService.updateType(dto);
    }


    /**
     * 修改分类禁止启用状态
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,Long id) {
        return categoryService.updateStatus(status,id);
    }


    /**
     * 根据类型分类查询
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result selectByList(Integer type){
        return categoryService.selectByList(type);
    }

}
